
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.team.sdsc.datamodel.*" %>

<%
     String event = request.getParameter("event");

     Network network = NetworkFactory.newInstance();
     Site site = network.getSites().get(0);
     Protocol protocol = network.getProtocol(4);

     // get all camera traps
     List<SamplingUnit> units = network.getSamplingUnits(site, protocol);

     // get all the camera traps whose photos are imported
     List<CameraTrap> iTraps = new ArrayList<CameraTrap>();
     if (event != null && !event.equals("")) { 
         iTraps = network.getImportedCameraTraps(event);
     }

     TreeSet<SamplingUnit> traps = new TreeSet<SamplingUnit>(new SamplingUnitNameComparator());
     for (SamplingUnit unit : units) {
        boolean found = false;
        for (CameraTrap trap : iTraps) {
	   if (unit.getId().intValue() == trap.getId().intValue()) {
	      found = true;
	      break;
	   }
	}

	if (!found) traps.add(unit);
     }

     //traps.addAll(units);

%>

{
   results: [

<%
    int k = 0;
    for (SamplingUnit unit : traps ) {
        if (unit instanceof CameraTrap) {
	    if (k > 0) {
	        out.println("      ,");
	    }
	    out.println("      { id: "+unit.getId()+", name: '"+unit.getName()+"' }" ); 
	    k++;
	}
    }
%>


  ]
}

